import React, { createContext, useContext, ReactNode } from 'react';

interface MCPContextType {
  callTool: <T>(toolName: string, args?: any) => Promise<T>;
}

const MCPContext = createContext<MCPContextType>({
  callTool: async () => {
    throw new Error('MCPContext not initialized');
  }
});

interface MCPProviderProps {
  children: ReactNode;
  callTool: <T>(toolName: string, args?: any) => Promise<T>;
}

export const MCPProvider: React.FC<MCPProviderProps> = ({ 
  children, 
  callTool 
}) => {
  return (
    <MCPContext.Provider value={{ callTool }}>
      {children}
    </MCPContext.Provider>
  );
};

export const useMCPContext = () => {
  const context = useContext(MCPContext);
  if (!context) {
    throw new Error('useMCPContext must be used within a MCPProvider');
  }
  return context;
};